package compiler

import (
	"gitee.com/engino/flow/impl/defn"
	"gitee.com/engino/flow/process"
)

//DecisionNode the execution node for decisions.
type DecisionNode struct {
	*defn.Decision
}

//GetName get the name of the decision node.
func (n *DecisionNode) GetName() string {
	return n.Name
}

//Execute execute the decision.
func (n *DecisionNode) Execute(inst process.Instance) error {
	for _, rule := range n.DecisionRules {
		if rule.Criteria == "true" {
			return process.Continue(inst, rule.Connector)
		}
	}
	return process.Continue(inst, n.DefaultConnector)
}
